package com.itheima.ai.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class gameController {


    private final ChatClient OpenAIChatClient;

    @RequestMapping(value = "/game",produces = "text/html;charset=UTF-8")
    public Flux<String> gameChat(String prompt,String chatId){
        return OpenAIChatClient
                .prompt()
                .user(prompt)
                .advisors(a->a.param(CONVERSATION_ID,chatId))
                .stream()
                .content();
    }
}
